// msilgc.cudahelper.cpp : Defines the exported functions for the DLL application.
//
#ifdef WIN32
#include "stdafx.h"
#endif

#include <cuda_runtime_api.h>

#ifdef WIN32
extern "C" __declspec(dllexport) int _GetNumberOfCudaDevicesAvailable();
extern "C" __declspec(dllexport) char* _GetDeviceName(int deviceId);
extern "C" __declspec(dllexport) int GetFastestCudaDeviceId();
#endif

int  GetNumberOfCudaDevicesAvailable() {
	int count = 0;
	cudaGetDeviceCount(&count);
	return count;
}

char* _GetDeviceName(int deviceId)
{
	cudaDeviceProp prop;
	cudaGetDeviceProperties(&prop, deviceId);
	return _strdup(&prop.name[0]);
}

int GetFastestCudaDeviceId() {
	int device_count = 0;
	cudaDeviceProp device_properties;
	cudaGetDeviceCount( &device_count );
	int max_gflops_device = 0;
	int max_gflops = 0;
	int current_device = 0;
	cudaGetDeviceProperties( &device_properties, current_device );
	max_gflops = device_properties.multiProcessorCount * device_properties.clockRate;
	++current_device;
	while( current_device < device_count )
	{
		cudaGetDeviceProperties( &device_properties, current_device );
		int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
		if( gflops > max_gflops )
		{
			max_gflops        = gflops;
			max_gflops_device = current_device;
		}
		++current_device;
	}
	return max_gflops_device;
}
